package com.jwds.digital.bios.business.service.rule.impl;

import com.jwds.digital.bios.business.core.constants.RuleCodeConstant;
import com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.DispatchParameterReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.mapper.dispatch.DispatchConfiguratMapper;
import com.jwds.digital.bios.business.core.infrastructure.vo.belt.BeltRouteTargetHisRespVO;
import com.jwds.digital.bios.business.core.infrastructure.vo.feign.FlowBasicRespVO;
import com.jwds.digital.bios.business.rpc.feign.BasicStockBinFeign;
import com.jwds.digital.bios.business.service.rule.DispatchRuleSortInterface;
import com.jwds.digital.bios.business.service.service.dispatch.IDispatchConfiguratService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/*
 *
 *
 *       流程路线的规则实现类
 *
 * */
@Slf4j
@Component
public class ProcessRouteDemo implements DispatchRuleSortInterface {
    @Autowired
    DispatchConfiguratMapper dispatchConfiguratMapper;
    @Autowired
    IDispatchConfiguratService dispatchConfiguratService;
    @Override
    public String getRuleCode() {
        //return RuleCodeConstant.RULE_DEMO1;
        return null;
    }

    @Override
    public List<DispatchParameterReqDTO> sortProcess(List<DispatchParameterReqDTO> dataList) {
        List<DispatchParameterReqDTO> resultList = new ArrayList<>();
        List<FlowBasicRespVO> flowBasicRespVOList = new ArrayList<>();
        dataList.stream().forEach(d->{
            //flowBasicRespVOList.addAll(d.getFlowList());
        });

        List<BeltRouteTargetHisRespVO> beltRouteTargetHisRespVOS = dispatchConfiguratService.LineEnergy(flowBasicRespVOList);

        List<String> collect = beltRouteTargetHisRespVOS
                .stream().sorted(Comparator.comparing(BeltRouteTargetHisRespVO::getTonPowerConsumption).reversed())
                .map(b->{return b.getFlowName();})
                .collect(Collectors.toList());

        List<FlowBasicRespVO> collected = collect.stream().map(c -> {
            FlowBasicRespVO flowBasicRespVO = new FlowBasicRespVO();
            flowBasicRespVO.setFlowName(c);
            return flowBasicRespVO;
        }).collect(Collectors.toList());

        for (DispatchParameterReqDTO dispatchParameterReqDTO : dataList) {
           // dispatchParameterReqDTO.setFlowList(collected);
            resultList.add(dispatchParameterReqDTO);
        }
        return resultList;
    }
}
